﻿using B.S.BaseData.Api.Read.Command;
using B.S.BaseData.ErrorCode;
using B.S.BataBase.Domain.DTO;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.Api.Read.Controllers
{
    /// <summary>
    /// 基础数据 -API  -读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ManagementController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        public ManagementController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 角色列表显示
        /// </summary>
        /// <param name="command">参数</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<APIResult<ApiPaging<RoleDTO>>> RoleShow([FromQuery]RoleShowCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 用户列表显示
        /// </summary>
        /// <param name="command">参会苏</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<APIResult<ApiPaging<UserDTO>>> UserShow([FromQuery]UserShowCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="command">用户参数</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<APIResult<LoginDTO>> Login([FromQuery]LoginCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 登录权限列表显示
        /// </summary>
        /// <param name="pathIds">路径ID列表，用逗号分隔</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<APIResult<List<PathDTO>>> PathShow([FromQuery]string pathIds)
        {
            PathShowCommand command = new PathShowCommand();
            command.Paths = pathIds.Split(',').Select(item => Convert.ToInt64(item)).ToList();
            return await _mediator.Send(command);
        }
    }
}
